package com.ai.http;

import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import java.io.FileOutputStream;
import java.io.IOException;

public class commonT {

    public static void downloadFile(String url, String filename) {
        RestTemplate restTemplate = new RestTemplate();

        try {
            // 发送 GET 请求并接收响应
            ResponseEntity<byte[]> response = restTemplate.getForEntity(url, byte[].class);

            // 检查响应状态码
            if (response.getStatusCode().is2xxSuccessful()) {
                // 获取字节数据
                byte[] fileBytes = response.getBody();

                // 将数据写入文件
                try (FileOutputStream fileOutputStream = new FileOutputStream(filename)) {
                    fileOutputStream.write(fileBytes);
                }
            } else {
                System.out.println("Failed to download the file: " + response.getStatusCode());
            }
        } catch (IOException e) {
            System.out.println("Error occurred: " + e.getMessage());
        }
    }

    public static void main(String[] args) {
        String originalText = "\"：\\n\\n\"你好";
        String modifiedText = originalText

                .replace("\\n", "<br>")
                .replaceAll("\"","");
        System.out.println(modifiedText);




    }
}

